package com.example.demo;

import com.example.demo.dao.TestDao;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;

@RestController
public class TestController {

    @Autowired
    TestDao testDao;

    @PostMapping("/uac/api/v1/labor_task/add")
    public Map getParams(@RequestBody Map map){
        return map;
    }

    @PostMapping("/uac/api/v1/labor_task/finish")
    public Map getDelParams(@RequestBody Map map){
        return map;
    }

    @RequestMapping("/param/{v}")
    public Map getParam(@PathVariable String v,@RequestParam Map map){

        map.put("v",v);
        return map;

    }

    @RequestMapping("/aa")
    public List aa(){

        return testDao.selectA();

    }

    @RequestMapping("/bb")
    public void bb(){

        HashMap<Object, Object> map = new HashMap<>();
        map.put("date",new Date());
        testDao.insert(map);

    }
    @RequestMapping("/cc")
    public void cc(){

        HashMap<Object, Object> map = new HashMap<>();
        map.put("date",new Date());
        testDao.insert2(map);

    }

    @RequestMapping("/map")
    public Object returnMap() throws IOException {

        HashMap<Object, Object> map1 = new HashMap<>();
        HashMap<Object, Object> map2 = new HashMap<>();

        map2.put("aa",null);
        map1.put("data",map2);

        ObjectMapper mapper = new ObjectMapper();
        mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
        String s = mapper.writeValueAsString(map1);
        Map readValue = mapper.readValue(s, Map.class);
        return readValue;
    }


    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("aaa");
        for(int i=0; i<list.size(); i++){
            list.remove(i);
        }
        /*for(String s : list) {
            System.out.println(s);
            list.remove(s);
        }*/
    }

}
